<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/comm/mytags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>后台管理系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="后台管理系统">
    <link rel="shortcut icon" href="${ctx}/static/img/favicon.ico">
    <link rel="stylesheet" href="${ctx}/static/layui_v2/css/layui.css">
    <link rel="stylesheet" href="${ctx}/static/css/global.css">
    <link rel="stylesheet" type="text/css" href="${ctx}/static/css/common.css" media="all">
    <link rel="stylesheet" type="text/css" href="${ctx}/static/css/personal.css" media="all">
    <link rel="stylesheet" type="text/css" href="http://at.alicdn.com/t/font_9h680jcse4620529.css">
    <script src="${ctx}/static/layui_v2/layui.js"></script>


<body>
<div class="larry-grid layui-anim layui-anim-upbit larryTheme-A ">
    <div class="larry-personal">
        <div class="layui-tab">
            <blockquote class="layui-elem-quote mylog-info-tit">
                <div class="layui-inline">
                    <form class="layui-form" id="userSearchForm">
                        <div class="layui-input-inline" style="width:145px;">
                            <input type="text" name="searchContent" value="" placeholder="输入用户名或手机号" class="layui-input search_input">
                        </div>
                        <a class="layui-btn userSearchList_btn" lay-submit lay-filter="userSearchFilter"><i class="layui-icon larry-icon larry-chaxun7"></i>查询</a>
                        <div class="layui-inline">
                            <a class="layui-btn layui-btn-normal paramSetting_btn"> <i class="layui-icon larry-icon larry-xinzeng1"></i>用户每天可博饼次数设置</a>
                        </div>
                    </form>
                </div>

            </blockquote>
            <div class="larry-separate"></div>
            <!-- 用户列表 -->
            <div class="layui-tab-item layui-show" style="padding: 10px 15px;">
                <table id="userTableList"  lay-filter="userTableId"></table>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    layui.config({
        base : "${ctx}/static/js/"
    }).use(['form', 'table', 'layer','common'], function () {
        var $ =  layui.$,
                form = layui.form,
                table = layui.table,
                layer = layui.layer,
                common = layui.common;
        /**用户表格加载*/
        table.render({
            elem: '#userTableList',
            url: '${ctx}/getUserList',
            id:'userTableId',
            method: 'post',
            height:'full-140',
            skin:'row',
            even:'true',
            size: 'md',
            cols: [[
                {field:'userId', title: '用户ID',width: 120 },
                {field:'userName', title: '用户姓名',width: 100},
                {field:'tel', title: '手机号码',width: 150},
                {field:'dayJoinCount', title: '今日剩余博饼次数',width: 150},
                {field:'credits', title: '拥有积分',width: 100},
                {field:'totalJoinCount', title: '总博饼次数',width: 100},
                {field:'userStatus', title: '用户状态',width: 90,templet: '#userStatusTpl'},
                {field:'createTime', title: '创建时间',width: 150},
                {fixed:'right', title: '操作', align:'center',width: 100, toolbar: '#userBar'}
            ]],
            page: true,
            limit: 10//默认显示10条
        });

        /**查询*/
        $(".userSearchList_btn").click(function(){
            //监听提交
            form.on('submit(userSearchFilter)', function (data) {
                if(isNaN(data.field.searchContent)){
                    table.reload('userTableId',{
                        where: {
                            userName:data.field.searchContent
                        },
                        height: 'full-140'
                    });
                }
                else{
                    table.reload('userTableId',{
                        where: {
                            tel:data.field.searchContent
                        },
                        height: 'full-140'
                    });
                }

            });

        });

        $(".paramSetting_btn").click(function () {
            var url =  "${ctx}/paramSetting";
            common.cmsLayOpen('设置用户每天可博饼次数',url,'600px','200px');
        });

        /**监听工具条*/
        table.on('tool(userTableId)', function(obj){
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值

            //修改用户
            if(layEvent === 'user_edit') {
                var userId = data.userId;
                var url =  "${ctx}/userEdit?userId="+userId;
                common.cmsLayOpen('编辑用户',url,'600px','420px');
            }
    });


    });
</script>
<!-- 用户状态tpl-->
<script type="text/html" id="userStatusTpl">

    {{# if(d.userStatus == 1){ }}
    <span class="label label-success ">1-有效</span>
    {{# } else if(d.userStatus == 0){ }}
    <span class="label label-danger ">0-失效</span>
    {{# } else { }}
    {{d.userStatus}}
    {{# }  }}
</script>


<!--工具条 -->
<script type="text/html" id="userBar">
    <div class="layui-btn-group">
            <a class="layui-btn layui-btn-small user_edit" lay-event="user_edit"><i class="layui-icon larry-icon larry-bianji2"></i> 编辑</a>
    </div>
</script>



</body>
</html>